using System;
using System.Collections.Generic;
using System.IO;
using System.Web.UI;
using SouthernLand.Common;

namespace SouthernLand.Controls
{
    public partial class Advertise : UserControl
    {
        public int AdvPosition { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            List<Common.BOL.Advertise.Advertise> list =
                Common.BOL.Advertise.Advertise.GetAdvertiseByPosition(AdvPosition);
            if (list!=null && list.Count>0)
            {
                rptAdvertise.DataSource = list;
                rptAdvertise.DataBind();    
            }
        }

        protected string GetAdvertise(string fileName, int width, int height)
        {
            if (Path.GetExtension(fileName).ToLower() == ".swf")
                return "<script>WriteObject('" + Globals.ApplicationPath + "UserUpload/Logo/" + fileName + "' ," + width +
                       "," + height + ");</script>";
            else
            {
                if (width > 0 && height > 0)
                    return "<img src='" + Globals.ApplicationPath + "UserUpload/Logo/" + fileName + "' border=0 width=" +
                           width + " Height=" + height + "   />";
                else if (width > 0)
                    return "<img src='" + Globals.ApplicationPath + "UserUpload/Logo/" + fileName + "' border=0 width=" +
                           width + " />";
                else if (height > 0)
                    return "<img src='" + Globals.ApplicationPath + "UserUpload/Logo/" + fileName + "' border=0 Height=" +
                           height + " />";
                else
                    return "<img src='" + Globals.ApplicationPath + "UserUpload/Logo/" + fileName + "' border=0 />";
            }
        }
    }
}